import apiClient from "./api-client";
import { HttpApi } from "./http-api";

export interface Posts {
  userId: number;
  id: number;
  title: string;
}

export interface User {
  id: number;
  name: string;
  username: string;
  email?: string;
}

class UserApi extends HttpApi {
  constructor() {
    super("/users");
  }

  getPosts() {
    const controller = new AbortController();
    const request = apiClient.get<Posts[]>("/posts", {
      signal: controller.signal,
    });
    return {
      request,
      cancel: () => controller.abort(),
    };
  }
}

export default new UserApi();
